
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>写日报</title>
    <link rel="stylesheet" type="text/css" href="mode/weui/weui.min.css"/>
    <link rel="stylesheet" type="text/css" href="web/res/fontawesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="webmain/css/rui.css">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/js.js"></script>
    <script type="text/javascript" src="js/jswx.js"></script>
    <script type="text/javascript" src="js/base64-min.js"></script>
    <script type="text/javascript" src="webmain/we/ying/ying.js"></script>
    <script type="text/javascript" src="mode/plugin/jquery-rockdoupull.js"></script>

    <style>

        body,html{background-color:#f1f1f1;overflow:hidden; background-color: white}
        .textarea1{width:calc(100% - 60px); margin:15px 20px 20px 20px;border: 1px gainsboro solid ; box-shadow:0px 0px 0px rgba(0,0,0,0);-webkit-appearance:none;height: 100px;font-size: 16px; padding: 5px; box-sizing: border-box"  placeholder="请在此处输入文本...}
        .textarea2{width:100%; border: 1px gainsboro solid ; margin-top: 10px; box-shadow:0px 0px 0px rgba(0,0,0,0);-webkit-appearance:none;height: 50px;font-size: 16px; padding: 5px; box-sizing: border-box}

    </style>
    <script>

        var mid = GetQueryStrings("mid");
        var edit = GetQueryStrings("edit");
        var json = <?=json_encode($xxdataArr)?>;
        var json1 = <?=json_encode($dailyArr)?>;
        var customer = <?=json_encode($customer)?>;
        var wqarr = <?=json_encode($wqarr)?>;

        var flog = 1;

        var edit;

        var time ;

        var wq = 0;


        window.onload=function(){

            time = gettime();
            var dateArray = time.split("-");
            var  date1 = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
            var currentWeek = "星期" + "日一二三四五六".charAt(date1.getDay());

            $('#current').html(''+ gettime() +'&nbsp&nbsp&nbsp'+currentWeek +'');

            if (edit == 1){

                document.title = "编辑";
                document.getElementById("change").style.visibility="hidden"
                for (var i =0;i<json1.length;i++){
                    var obj = json1[i];
                    if(obj.id == mid){

                        $('#content').html(obj.content);

                        var time1 = obj.dt;
                        var dateArray = time1.split("-");
                        var  date1 = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
                        var currentWeek = "星期" + "日一二三四五六".charAt(date1.getDay());
                        $('#current').html(''+ time1 +'&nbsp&nbsp&nbsp'+currentWeek +'');
                    }
                }

            }
        }

        function change(){

            flog = !flog;

            time = gettime();
            var dateArray = time.split("-");
            var  date1 = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
            var currentWeek = "星期" + "日一二三四五六".charAt(date1.getDay());

            $('#current').html(''+ gettime() +'&nbsp&nbsp&nbsp'+currentWeek +'');

            flog ? $('#change').html('补写昨天日报'): $('#change').html('写今日日报')

            $('#da').val(flog);

            document.getElementById("xx").style.visibility="hidden";

            $("#main").html('<textarea id="content" name="comment" class = "textarea1"></textarea>');

            $.ajax({
                type: 'POST',
                url: "http://oa.wxlion.com/index.php?a=write&m=ying&d=we&num=daily&show=we",
                 //url: "http://localhost/oa/public_html/index.php?a=write&m=ying&d=we&num=daily&show=we",
                data: {

                    change:1,
                    date: $('#da').val()
                },
                datatype: "json",
                success: function(data) {

                     var arr = eval(data);
                     wqarr = arr;


                },
                //调用出错执行的函数
                error: function(error1) {


                }
            });
        }


        function gettime(){

            flog ? i = 0:i = 1;

            var d = new Date;

            d.setDate(d.getDate() - i);

            var day=d.getDate()

            var month=d.getMonth() + 1

            var year=d.getFullYear()

            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }

            if (day >= 1 && day <= 9) {
                day = "0" + day;
            }

            var times = year + "-" + month + "-" + day;

            return times;

        }


        function lead(){

            var html = '';

             for(var i =0; i<wqarr.length;i++){

                 var n = i+1;
                 var obj = wqarr[i];
                 var customerName;

                 if(obj.customerId == 0){

                     html+=' <div style="margin:15px 20px 20px 20px;"><div id="explain'+ i +'">'+ n + '.&nbsp&nbsp说明:&nbsp&nbsp'+ obj.explain +'</div> <textarea id="content'+ i +'" name="comment" class = "textarea2"></textarea> </div>'


                 }else{
                     for(var m = 0; m<customer.length;m++){

                         var obj1 = customer[m];
                         if(obj1.id == obj.customerId){

                             customerName = obj1.name;
                             html+=' <div style="margin:15px 20px 20px 20px;"><span id="customer'+ i +'" style="display: inline-block">'+ n +'.&nbsp&nbsp拜访客户:&nbsp&nbsp'+ customerName +'</span> <div id="explain'+ i +'" style="margin-left: 20px;">说明:'+ obj.explain +'</div> <textarea id="content'+ i +'" name="comment" class = "textarea2"></textarea> </div>'
                         }
                     }
                 }
             }


             html += '<textarea id="content" style="width:calc(100% - 50px);" placeholder="输入其它备注..." name="comment" class = "textarea1"></textarea>'

             if(wqarr.length){
                  wq = 1 ;
                 $("#main").html(html);
             }else{
                 document.getElementById("xx").style.visibility="visible";
                 $('#xx').html(''+gettime()+'&nbsp没有外勤记录')
             }


        }

        function comment(){

           if(xxtime(flog)){

               var contents = '';

               if(wq){

                   for(var i =0; i<wqarr.length;i++){

                       var n = i+1;
                       var obj = wqarr[i];
                       var customerName;

                       if(obj.customerId == 0){

                           contents += $("#explain"+i).text();
                           contents += '\r\n&nbsp&nbsp&nbsp&nbsp备注:';
                           contents += $("#content"+i).val();
                           contents += '\r\n';

                       }else{
                           for(var m = 0; m<customer.length;m++){

                               var obj1 = customer[m];
                               if(obj1.id == obj.customerId){

                                   customerName = obj1.name;

                                   contents += $("#customer"+i).text();
                                   contents += '\r\n&nbsp&nbsp&nbsp&nbsp';
                                   contents += $("#explain"+i).text();
                                   contents += '\r\n&nbsp&nbsp&nbsp&nbsp备注:';
                                   contents += $("#content"+i).val();
                                   contents += '\r\n&nbsp&nbsp&nbsp&nbsp其它备注:';

                               }
                           }

                           contents += $("#content").val();
                           contents += '\r\n';

                       }
                   }
               }
               else{
                   contents += $("#content").val();
               }

               if(contents.length) {

                  if (edit == 1){

                      $.ajax({
                           type: 'POST',
                           url: "http://oa.wxlion.com/index.php?a=write&m=ying&d=we&num=daily&show=we",
                         // url: "http://localhost/oa/public_html/index.php?a=write&m=ying&d=we&num=daily&show=we",
                          data: {
                              mid: mid,
                              comment: contents,
                              date: $('#da').val(),
                              edits:1
                          },
                          datatype: "json",
                          success: function(data) {

                              window.history.go(-1);

                          },
                          //调用出错执行的函数
                          error: function(error1) {


                          }
                      });

                      return;
                  }


                   $.ajax({
                       type: 'POST',
                       url: "http://oa.wxlion.com/index.php?a=write&m=ying&d=we&num=daily&show=we",
                      // url: "http://localhost/oa/public_html/index.php?a=write&m=ying&d=we&num=daily&show=we",
                       data: {
                           mid: $('#mid').val(),
                           comment: contents,
                           date: $('#da').val()
                       },
                       datatype: "json",
                       success: function(data) {

                           window.history.go(-1);

                       },
                       //调用出错执行的函数
                       error: function(error1) {


                       }
                   });

               }
           }else{

               document.getElementById("xx").style.visibility="visible";
               $('#xx').html(''+time+'&nbsp是休息时间')
           }

        }

        function GetQueryStrings(name)
        {
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        }

       function xxtime(flog) {


           time = gettime();

           for (var n = 0; n<json.length;n++){

               var obj = json[n];
               if(obj.dt == time){

                   return false;
               }
           }
           return true;

       }

    </script>
</head>



<div  style="width: 100%; height: calc(100% - 10px);  overflow: auto; background-color: white;">

    <div style="flex-direction: row;display: flex;margin: 20px 20px 0px 20px; width: calc(100% - 40px);justify-content: space-between;align-items:center;">

        <sapn id = "current" ></sapn>

        <div onclick="change()" id="change" style="border: 1px black solid; padding: 5px;border-radius: 5px;visibility:visible">补写昨天日报</div>

    </div>

    <div onclick="lead()" style="width: 110px; text-align: center; margin: 20px 20px 0px 20px; border: 1px black solid; border-radius: 5px; padding: 3px;">导入外勤记录</div>

    <div id="main">

        <textarea id="content" name="comment" class = "textarea1"></textarea>


        <!--<div style="margin:15px 20px 20px 20px;">-->

            <!--<span style="display: inline-block">1. 客户:申明康</span>-->
            <!--<span style="display: inline-block; margin-left: 20px;">说明:去连城联络感情去连城联络感情去连城联络感情去连城联络感情去连城联络感情去连城联络感情</span>-->
            <!--<textarea id="content1" name="comment" class = "textarea2"></textarea>-->

        <!--</div>-->
        <!--<div style="margin:15px 20px 20px 20px;">-->

            <!--<span style="display: inline-block">1. 客户:申明康</span>-->
            <!--<span style="display: inline-block; margin-left: 20px;">说明:去连城联络感情去连城联络感情去连城联络感情去连城联络感情去连城联络感情去连城联络感情</span>-->
            <!--<textarea id="content2" name="comment" class = "textarea2"></textarea>-->

        <!--</div>-->

    </div>


    <input id="mid" type="hidden" name="mid">

    <input id="da" value=true type="hidden">

    <div  onclick="comment()" style="text-align: center; width: 90%; border-radius: 5px; height: 30px;line-height: 30px; margin: 10px 5% 10px 5%; padding: 5px 0px;  background-color: rgb(27,205,138); font-size: 16px">发表<div>

    <span id="xx" style="display: inline-block;margin: 20px; color: red;visibility:hidden"></span>

    </div>

</div>


</html>